/***************************************************
// FileName: UVideoDevice.h
// ClassName: UVideoDevice
// Description: initialize and use MicroView card
// Author: MicroView
// Modify: xwt
// Date: 2007-7-1
****************************************************/

#pragma once

#include "MVAPI.h"

class UVideoDevice
{
public:
	UVideoDevice(void);
	~UVideoDevice(void);

	HANDLE GetCurrentDevice()
	{
		return m_CurDev ;
	};
	static DWORD GetDeviceNumber()
	{
		return MV_GetDeviceNumber();
	};
	void InitVideoDevice();
	void FiniVideoDevice();
	void StartGrabDevice();
	void StartGrabOnDefault();
	void StopGrabDevice();
	void GrabSingle(PVOID pImageBuf);

	void SetVideoColor(int nLuma,int nContrast,int nStaturtion,int nHue)
	{
		if(m_CurDev)
		{
			MV_SetDeviceParameter(m_CurDev,ADJUST_LUMINANCE	,nLuma);
			MV_SetDeviceParameter(m_CurDev,ADJUST_CONTRAST	,nContrast);
			MV_SetDeviceParameter(m_CurDev,ADJUST_SATURATION,nStaturtion);
			MV_SetDeviceParameter(m_CurDev,ADJUST_HUE		,nHue);
		}
	};
	void GetVideoColor(int &nLuma,int &nContrast,int &nStaturtion,int &nHue)
	{
		if(m_CurDev)
		{
			nLuma		= MV_GetDeviceParameter(m_CurDev,ADJUST_LUMINANCE);
			nContrast	= MV_GetDeviceParameter(m_CurDev,ADJUST_CONTRAST);
			nStaturtion	= MV_GetDeviceParameter(m_CurDev,ADJUST_SATURATION);
			nHue		= MV_GetDeviceParameter(m_CurDev,ADJUST_HUE);
		}
	};
	void SetGrabSize(int nWidth,int nHeight)
	{
		if(m_CurDev)
		{
			MV_SetDeviceParameter( m_CurDev, GARB_IN_WIDTH , nWidth );
			MV_SetDeviceParameter( m_CurDev, GARB_WIDTH    , nWidth);
			MV_SetDeviceParameter( m_CurDev, GARB_IN_HEIGHT, nHeight );
			MV_SetDeviceParameter( m_CurDev, GARB_HEIGHT   , nHeight );
		}
	};
	void SetGrabBit(int nGrabBit)
	{
		if(m_CurDev)
		{
			MV_SetDeviceParameter( m_CurDev, GARB_BITDESCRIBE , nGrabBit );
		}
	};
	void GetGrabSize(int &nWidth,int &nHeight)
	{
		if(m_CurDev)
		{
			nWidth		= MV_GetDeviceParameter(m_CurDev,GARB_WIDTH);
			nHeight		= MV_GetDeviceParameter(m_CurDev,GARB_HEIGHT);
		}
	};
	void GetGrabBit(int &nGrabBit)
	{
		if(m_CurDev)
		{
			nGrabBit = MV_GetDeviceParameter( m_CurDev, GARB_BITDESCRIBE);
		}
	};
	void SetVideoWindow(HWND nWnd)
	{
		if(m_CurDev)
		{
			CRect WinRect ;
			::GetWindowRect(nWnd,&WinRect);
			MV_SetDeviceParameter( m_CurDev, DISP_WHND		, (DWORD)(nWnd) );
			MV_SetDeviceParameter( m_CurDev, DISP_LEFT		, 0 );
			MV_SetDeviceParameter( m_CurDev, DISP_TOP		, 0 );
			MV_SetDeviceParameter( m_CurDev, DISP_WIDTH		, WinRect.right-WinRect.left);
			MV_SetDeviceParameter( m_CurDev, DISP_HEIGHT	, WinRect.bottom-WinRect.top);
		}
	}

	void SetCallBack(CALLBACKFUNC nFun,PVOID nContext)
	{
		if(m_CurDev)
		{
			MV_SetCallBack( m_CurDev, nFun, nContext, BEFORE_PROCESS);
		}
	};
private:
	DWORD	m_TotalDevice ;
	HANDLE  m_CurDev ;
	BOOL	m_InitDeviceFlag ;
	BOOL	m_StartGrabFlag ;
	int m_CurLuma,m_CurContrast,m_CurSaturation,m_CurHue;
	int m_GrabWidth,m_GrabHeight,m_GrabBitDescribe;
};
